#!/bin/bash

if [[ -f $HOME/.tmux.conf ]]; then echo "tmux is installed"; exit 0; fi

SUDO="sudo "
if [[ $(id -u) -eq 0 ]]; then SUDO=""; fi

$SUDO apt install tmux -y

git clone https://gitee.com/wyanlord/.tmux.git $HOME/.tmux
cp $HOME/.tmux/.tmux.conf $HOME/
cp $HOME/.tmux/.tmux.conf.local $HOME/
sed -i '/C-a/d' $HOME/.tmux.conf
rm -rf $HOME/.tmux

cat << "EOF" | tee -a $HOME/.zshrc
function htmux { cat ~/.tmux.md; }
EOF

cat << "EOF" | tee $HOME/.tmux.md
# 会话

tmux new -s [name]      # 新建会话
tmux attach -t [name]   # 进入会话
C - b => $  # 命名会话
C - b => s  # 切换会话
C - b => d  # 分离会话
C - b => ~  # 信息缓存
C - b => [  # 复制模式

# 窗口

C - b => c  # 新建窗口
C - b => w  # 列举窗口
C - b => ,  # 命名窗口
C - b => .  # 排序窗口
C - b => f  # 查找窗口
C - b => n  # 跳转到下一个窗口
C - b => p  # 跳转到上一个窗口
C - b => 0  # 跳转到指定窗口0

# 屏幕

C - b => %  # 左右分屏
C - b => "  # 上下分屏
C - b => x  # 关闭分屏
C - b => -> # 跳转分屏
C - b => \s # 变换分屏
C - b => o  # 遍历分屏
C - b => z  # 缩放分屏
EOF
